package com.beetlestech.nfe.main.biz.com.impl;

import java.sql.Time;
import java.util.Date;

import com.beetlestech.nfe.fw.core.biz.AbstractDBLogic;
import com.beetlestech.nfe.main.biz.com.HbUploadExamination;
import com.beetlestech.nfe.main.biz.constant.CommonConstant;
import com.beetlestech.nfe.main.biz.constant.CtgCodeConstant;
import com.beetlestech.nfe.main.biz.constant.HbMessageCode;
import com.beetlestech.nfe.main.db.constant.SQLConstant;
import com.beetlestech.nfe.main.db.tbl.ExaminationdocDTO;
import com.beetlestech.nfe.main.db.tbl.MstfileDTO;







public class HbUploadExaminationImpl extends AbstractDBLogic implements HbUploadExamination, CtgCodeConstant, HbMessageCode, CommonConstant, SQLConstant {
	protected static final String HW_DETAIL = "作业详细表";
	protected static final String MST_FILE = "文件表";
	@Override
	public void UploadExamination(
			String exname,
			String	 path,
			Integer type,
			String forwardSlash
	){
				// path转换
				String strPath = path.replaceAll(forwardSlash, "/");
			
				// mst_file表插入
				MstfileDTO mstfileDTO = new MstfileDTO();
				String[] temp = strPath.split("files");
				strPath="files"+temp[1];
				mstfileDTO.setpath(strPath);
				mstfileDTO.settype(0);
				
			//对DB执行操作
				updateDAO.updateOne(MstfileDTO.INSERT, mstfileDTO, M10040WS, MST_FILE);
				
				
				ExaminationdocDTO exDTO=new ExaminationdocDTO();
				Date date=new Date();
				Time send_time=new Time(date.getTime());
				java.sql.Date sendSql= new java.sql.Date(date.getTime());
				exDTO.setname(exname);
				exDTO.settype(type);
				exDTO.setsenderid(0);
				exDTO.setfileid(mstfileDTO.getfileid());
				exDTO.setsenddate(sendSql);
				exDTO.setsendtime(send_time);
				
				
				
				updateDAO.updateOne(ExaminationdocDTO.INSERT, exDTO, M10040WS, HW_DETAIL);
				
		}
	@Override
	public String DownloadAdminExamination(Integer ExId){
		ExaminationdocDTO exDTO=new ExaminationdocDTO();
		exDTO.setexaminationdocid(ExId);
		exDTO = queryDAO.queryForObject(ExaminationdocDTO.EQUAL_SEARCH, exDTO);
		MstfileDTO mstfileDTO = new MstfileDTO();
		mstfileDTO.setfileid(exDTO.getfileid());
		mstfileDTO = queryDAO.queryForObject(MstfileDTO.EQUAL_SEARCH, mstfileDTO);
		String path=mstfileDTO.getpath();
		return path;
	}

}
